# 二分查找
import random


def binary_search(li, val):
    left = 0
    right = len(li) - 1
    while left <= right:  # 候选区有值
        mid = (left + right) // 2  # 取中间索引
        if li[mid] == val:
            return mid
        elif li[mid] > val:  # 查找的值在mid左侧
            right = mid - 1
        else:  # 查找的值在mid右侧
            left = mid + 1
    else:
        return None


lis = list(range(3,15))
print(lis)
print(binary_search(lis, 5))
